package com.lry.route;

import com.lry.entity.Product;
import com.lry.handler.ProductHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class BaseRouter {

    @Bean
    public RouterFunction<ServerResponse> routes(ProductHandler myWebHandler) {

        return RouterFunctions.route()
                .POST(RoutePath.save, myWebHandler::save)
                .POST(RoutePath.saveForm, RequestPredicates.accept(MediaType.APPLICATION_FORM_URLENCODED), myWebHandler::save)
                .GET(RoutePath.find, myWebHandler::find)
                .DELETE(RoutePath.delete, myWebHandler::delete)
                .PUT(RoutePath.update, myWebHandler::update)
                .GET(RoutePath.findAll, myWebHandler::findAll)
                .GET(RoutePath.findAllPage, myWebHandler::findAllByPage)
                .POST(RoutePath.findByCategory, myWebHandler::findByCategoryPage)
                .POST(RoutePath.saveMany, myWebHandler::saveMany)
                .GET(RoutePath.findStock, myWebHandler::findStock)
                .build();
    }

}